import Vue from 'vue'
import VueRouter from 'vue-router'
import axios from "../axios"
import store from '../store/index.js'

Vue.use(VueRouter)
// export default{
// mode:"history",
const routes = [{
		path: "/login",
		name: "Login",
		component: () => import('@/views/Login1.vue')
	},
	{
		path: "/",
		name: "Home",
		component: () => import('@/views/Home.vue'),
		// meta:{
		// 	requireAuth:true
		// },
		children: [

			{
				path: "admin",
				name: "SysAdmin",
				component: () => import('@/views/wwt/Admin.vue')
			},
			{
				path: "authority",
				name: "SysAuthority",
				component: () => import('@/views/wwt/Authority.vue')
			},
      
			{
				path: "/goods",
				name: "goods",
				component: () => import('@/views/xwk/Goods.vue'),
			},
			{
				path: "/addgoods",
				name: "add-goods",
				component: () => import('@/views/xwk/AddGoods.vue'),
			},
			{
				path: "/edit-goods",
				name: "edit-goods",
				component: () => import('@/views/xwk/EditGoods.vue'),
			},
			{
				path: "/params",
				name: "params",
				component: () => import('@/views/xwk/Params.vue'),
			},
            {
					path:"/data",
					name:"Data",
					component:()=>import('@/views/zht/Data.vue')
				},
            {
					path:"/notice",
					name:"Notice",
					component:()=>import('@/views/zht/Notice.vue')
				},
			{
				path: "order",
				name: "order",
				component: () => import('@/views/ys/Order.vue'),
			},
			{
				path: "addorder",
				name: "addorder",
				component: () => import('@/views/ys/AddOrder.vue'),
			},
			{
				path: "editorder",
				name: "editorder",
				component: () => import('@/views/ys/EditOrder.vue'),
			},
			{
				path: "user",
				name: "user",
				component: () => import('@/views/zc/User.vue'),
			},
			{
				path: "adduser",
				name: "adduser",
				component: () => import('@/views/zc/AddUser.vue'),
			},
			{
				path: "edituser",
				name: "edituser",
				component: () => import('@/views/zc/EditUser.vue'),
			},

		]
	},


]
// }
const router = new VueRouter({
	mode: 'history',
	routes
})


//动态绑定路由，根据权限来进行路由的渲染
router.beforeEach((to, from, next) => {

	axios.get("/system/nav", {

		headers: {
			//获取信息
			Authorization: localStorage.getItem("token")
		}
	}).then(res => {

		console.log(res.data.data)
		// 拿到navlist
		store.commit("setNavList", res.data.data.navs)
		//获取用户权限
		store.commit("setAuthList", res.data.data.authorities)

		console.log(store.state.navs.navList)
	})
	next()
})

export default router
